define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function(){
	    this.loadDone = false;
	    this.pullupTime = 0;
		this.callParent();
	};
	
	Model.prototype.getPhoneNum = function(phone){
		return 'tel:'+phone;
	};

	Model.prototype.phoneDataCustomRefresh = function(event){
	    
	    if(event.source.count() < event.offset){
	    	return;
	    }
	    this.comp("popOver1").show();
	    var me = this;
	    var page = event.offset/event.limit + 1;
		var getPhoneUrl = this.getParentModel().serverUrl + "/ex_community/a/api/community/getPhone?callback=?";
		$.getJSON(
				getPhoneUrl,
				{
					pageSize:event.limit,
					pageNo:page
				},
				function(data){
					if(data && data.data){
						event.source.loadData(data.data,true,null,event.offset,true);
						 me.comp("popOver1").hide();
						 me.loadDone = true;
						
					}
				}
		);
	   
	

	};

	Model.prototype.scrollView1PullDown = function(event){
		this.comp("phoneData").refreshData();
	};

	Model.prototype.scrollView1PullUp = function(event){
	        if(this.loadDone){
	            this.loadDone = false;
	        	this.comp("phoneData").loadNextPageData();
		
	        }
	        
	};



	Model.prototype.showSearchButtonClick = function(event){
		$('.search-panel').slideToggle();
	};



	Model.prototype.searchButtonClick = function(event){
		
		var page = event.offset/event.limit + 1;
	    var searchUrl = this.getParentModel().serverUrl + "/ex_community/a/api/community/getPhone?callback=?";
	    var searchName = this.comp("searchContent").val();
	    if(searchName){
//	    	var companyId = this.getParentModel().getCompanyId();
		    var me = this;
		     $.getJSON(searchUrl,{"pageSize":event.limit,"pageNo":page,'name':searchName},function(data){
		    	  me.comp("phoneData").clear();
		    	  if(data && data.data){
		    	        me.isInSearch = true;
	    		    	  
	        		    me.comp("phoneData").loadData(data.data,true);
	    		    }     
		     
		     });
	    
	    }
		
	    
//	    if(event.source.count() < event.offset){
//	    	return;
//	    }
//	    this.comp("popOver1").show();
//	    var me = this;
//	    var searchName = this.comp("searchContent").val();
//	    var page = event.offset/event.limit + 1;
//		var getPhoneUrl = this.getParentModel().serverUrl + "/ex_community/a/api/community/getPhone?callback=?";
//		$.getJSON(
//				getPhoneUrl,
//				{
//					pageSize:event.limit,
//					pageNo:page,
//					name:searchName
//				},
//				function(data){
//					if(data && data.data){
//						event.source.loadData(data.data,true,null,event.offset,true);
//						 me.comp("popOver1").hide();
//						 me.loadDone = true;
//						
//					}
//				}
//		);
	   
		
	};



	return Model;
});